package com.example.zqm.git72.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.zqm.git72.Activity.SearchClubActivity;
import com.example.zqm.git72.Adapter.ClubListAdapter;
import com.example.zqm.git72.JavaBean.Club;
import com.example.zqm.git72.Model.ClubModel;
import com.example.zqm.git72.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ClubFragment extends Fragment {
    public List<Club> clubs;
    private RecyclerView recyclerView;
    private  ImageView search;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate( R.layout.fragment_club, container, false);
        recyclerView = (RecyclerView) v.findViewById(R.id.rrr);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));//设置布局
        shouData();
        search=(ImageView)v.findViewById(R.id.search);
        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), SearchClubActivity.class);
                startActivity(intent);
            }
        });
        return v;
    }
    private void shouData() {

//        //联网获取网络上的数据
//        Retrofit retrofit = new Retrofit.Builder()
//                .baseUrl("http://172.24.10.130:8080/")
//                .addConverterFactory(GsonConverterFactory.create())
//                .build();
//        ShopService shopService= retrofit.create(ShopService.class);

        ClubModel clubModel = new ClubModel();
        Call<List<Club>> call = clubModel.getList();

        call.enqueue(new Callback<List<Club>>() {
            @Override
            public void onResponse(Call<List<Club>> call, Response<List<Club>> response) {
                clubs = response.body();
                recyclerView.setAdapter(new ClubListAdapter(getActivity(), clubs));//设置适配器

            }

            @Override
            public void onFailure(Call<List<Club>> call, Throwable t) {

            }
        });

    }

}
